package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzSettings;
import com.jy.adscm.operation.mscyb.bean.JqzzSettingParts;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqbzSettingsMapper;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqzzSettingPartsMapper;
import com.jy.adscm.operation.mscyb.service.JqzzSettingPartsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-21
 */
@Service
public class JqzzSettingPartsServiceImpl extends ServiceImpl<JqzzSettingPartsMapper, JqzzSettingParts> implements JqzzSettingPartsService {
    @Autowired
    JqbzSettingsMapper jqbzSettingsMapper;

    @Override
    public List<JqzzSettingParts> selectJqzzSettingPartsByPid(String pid) throws AdscmSystemException {
        Wrapper<JqzzSettingParts> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",pid);
        List<JqzzSettingParts> jqzzSettingParts = super.selectList(wrapper);
        for (JqzzSettingParts jqzzSettingPart : jqzzSettingParts) {
            JqbzSettings jqbzSettings = jqbzSettingsMapper.selectById(jqzzSettingPart.getCid());
            if(AdscmBaseUtils.getInstance().isNotEmpty(jqbzSettings,null)){
                jqzzSettingPart.setName(jqbzSettings.getName());
                jqzzSettingPart.setCode(jqbzSettings.getCode());
            }
        }
        return jqzzSettingParts;
    }

    @Override
    public List<JqbzSettings> selectAll(Integer id) throws AdscmSystemException {
        Wrapper<JqbzSettings> wrapper =new EntityWrapper<>();
        wrapper.eq("type",id);
        wrapper.eq("isEnable",1);
        List<JqbzSettings> jqbzSettings = jqbzSettingsMapper.selectList(wrapper);
        return jqbzSettings;
    }
}
